#ifndef PARSERBASE_H
#define PARSERBASE_H

#include <string>
#include <vector>

//Base non-template functional for parser(tokenizer) of strings
//parse or tokenize string "1,,,,2,,,3,4"->{1},{2},{3},{4}
class CParserBase{
public:
    typedef std::string::const_iterator     str_ptr_t;
    typedef std::pair<str_ptr_t, str_ptr_t> str_interval_t;
    typedef std::vector<str_interval_t>     poser_t;
    typedef poser_t::const_iterator         poser_ptr_t;
	
	//iterator for STL flavour
	class const_iterator{
	public:						const_iterator(poser_ptr_t const &pos);
								const_iterator(const_iterator const &another);
		std::string operator	*()const;
		void operator 			++();
		bool operator			==(const_iterator const &another)const;
		bool operator			!=(const_iterator const &another)const;
		const_iterator &operator =(const_iterator i);
	private:
		poser_ptr_t	real_iterator;
	};

					//delimiter(s) - charecters which divide string to part
					CParserBase(char delimiter);
					CParserBase(std::string const &delimiters);
					~CParserBase();
					
	const_iterator	cbegin()const;
	const_iterator	cend()const;

    std::string 	getDelimiter()const;
    void        	setDelimiter(std::string const &delimiters);

    void        	parseString(std::string const &str);

    size_t      	size()const;


    bool        	getPart(size_t start, size_t stop, std::string &result)const;
    bool        	getTail(size_t start, std::string &result)const;
    bool        	getStart(size_t stop, std::string &result)const;
    bool        	getElement(size_t i, std::string &result)const;
	
	//unsafe - same functional but no check for errors
    std::string 	unsafe_getTail(size_t start)const;    
    std::string 	unsafe_getStart(size_t stop)const;
    std::string 	unsafe_getPart(size_t start, size_t stop)const;
    std::string 	unsafe_getElement(size_t i)const;

protected:
    std::string         delimiters;
    std::string const   *str;
    poser_t				poses;
};


#endif // PARSERBASE_H
